<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title><{webcontrol type='GetAppInf' varName='systemV'}></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=0">
    <{webcontrol type='LoadJsCss' src="Resource/Script/layui/layui/css/layui.css"}>
    <{webcontrol type='LoadJsCss' src="Resource/Script/layui/style/admin.css"}>

    <{webcontrol type='LoadJsCss' src="Resource/Script/Print/LodopFuncs.js"}>
    <{webcontrol type='LoadJsCss' src="Resource/Script/layui/layui/layui.js"}>
    <{webcontrol type='LoadJsCss' src="Resource/Script/jquery.1.9.1.js"}>
    <style type="text/css">
        .layui-input{display: inline-block;width: 100px;height: 30px;}
        #prn { position:fixed; bottom:10px; right:150px;}
        #prn input,a {  background-color: #0362fd !important; border:0px; color: #fff !important; font-family: '宋体';cursor: pointer; outline: medium none; font-size:14px; padding: 7px 14px;}
        .layui-form-label{width: 150px;}
    </style>
    <script type="text/javascript">
        var object = <{$row|@json_encode}>;
        var objectData = <{$objectData|@json_encode}>;
        var scode = object.printConfig.Senior || '';
        layui.config({
          base: 'Resource/Script/layui/' //静态资源所在路径
        }).extend({
          index: 'lib/index.js?ver=1.1'
        }).use(['index', 'form'], function(){
            var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,form = layui.form;

            form.render(null, 'component-form-element');
            element.render('breadcrumb', 'breadcrumb');

        });
    </script>
</head>
<body>
    <div class="layui-fluid" id="LAY-component-grid-all" lay-filter="component-form-element">
        <div class="layui-card">
            <div class="layui-row layui-col-space10 layui-form">
                <div class="layui-col-lg24">
                    <div class="layui-card-header">设置标签打印的配置信息</div>
                    <div class="layui-card">
                        <div class="layui-form-item">
                            <label class="layui-form-label">模版名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="printName" placeholder="" autocomplete="off" class="layui-input" value="<{$row.printConfig.printName}>">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否默认模版：</label>
                            <div class="layui-col-md1">
                                <select name="isDefault" lay-verify="required" lay-search >
                                    <option value="0" <{if $row.isDefault=='0' }>selected<{/if}>>否</option>
                                    <option value="1" <{if $row.isDefault=='1' }>selected<{/if}>>是</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">选择产品分类：</label>
                            <div class="layui-col-md1">
                                <select id="proKind" name="proKind" lay-filter="select_proKind" <{if $type}>disabled<{/if}>>
                                    <option value="">请选择</option>
                                    <{foreach from=$prokind item = item}>
                                    <option value="<{$item.value}>" <{if $row.kindId==$item.value }>selected<{/if}>><{$item.text}></option>
                                    <{/foreach}>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">标签模板：</label>
                            <div class="layui-form-mid layui-word-aux">
                                二维码
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">字体大小：</label>
                            <div class="layui-col-md1">
                                <select name="fontSize" lay-verify="required" lay-search>
                                    <option value="9" <{if $row.printConfig.fontSize=='9' }>selected<{/if}>>9号</option>
                                    <option value="10" <{if $row.printConfig.fontSize=='10' }>selected<{/if}>>10号</option>
                                    <option value="11" <{if $row.printConfig.fontSize=='11' }>selected<{/if}>>11号</option>
                                    <option value="12" <{if $row.printConfig.fontSize=='12' }>selected<{/if}>>12号</option>
                                    <option value="13" <{if $row.printConfig.fontSize=='13' }>selected<{/if}>>13号</option>
                                    <option value="14" <{if $row.printConfig.fontSize=='14' }>selected<{/if}>>14号</option>
                                    <option value="15" <{if $row.printConfig.fontSize=='15' }>selected<{/if}>>15号</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">纸张宽度：</label>
                            <div class="layui-input-block">
                                <input type="text" name="width" placeholder="" autocomplete="off" class="layui-input" value="<{$row.printConfig.pageWidth}>">(mm)
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">纸张高度：</label>
                            <div class="layui-input-block">
                                <input type="text" name="height" placeholder="" autocomplete="off" class="layui-input" value="<{$row.printConfig.pageHeight}>">(mm)
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" id="logo">
                                    <i class="layui-icon">&#xe67c;</i>上传logo
                                </button>
                                <input type="hidden" name="pic" id="pic" value="<{$row.printConfig.pic.url}>">
                            </div>
                        </div>
                        <input type="hidden" id="id" name="id" value="<{$row.id}>">
                        <input type="hidden" id="scode" name="scode" value="">
                        <div class="layui-card-header" style="margin-top: 5px">设置排版</div>
                        <div class="layui-card">
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn layui-btn-primary" onclick="prn1_design()">设置打印排版</button>
                                    <button class="layui-btn layui-btn-primary" onclick="scode=''">清空排版</button>
                                    <button class="layui-btn" onclick="prn1_preview()">打印预览</button>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn layui-btn-normal" onclick="submit()">提交排版</button>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-header" style="margin-top: 5px">操作说明</div>
                        <div class="layui-card">
                            <span style="color: red;margin: 5px 0px 0px 15px;">第一步:设置标签打印配置信息;</span></br><span style="color: red;margin: 5px 0px 0px 15px;">第二步:必须先设置打印排版！！！然后提交排版</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        var controller = "<{$smarty.get.controller}>"
        //定义几个变量
        layui.use('upload', function(){
            var upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#logo' //绑定元素
                ,url: "?controller="+controller+"&action=AddPics" //上传接口
                ,done: function(res){
                    //上传完毕回调
                    $('#pic').attr('value',res.bpic);
                    layer.msg('上传logo成功!');
                }
                ,error: function(){
                    //请求异常回调
                    layer.msg('上传logo失败!请重新上传');
                }
            });
        });
        layui.use(['form'], function() {
            form=layui.form;
            form.on('select(select_proKind)', function(data){
                var url = '?controller=Jichu_ProKind&action=GetExtendArr';
                var params = {id:data.value};
                $.post(url,params,function(json){
                    object.printConfig = json.config;
                    objectData = json.config.objectData;
                },'json');
            });
        });

        var LODOP;
        function setup() {
            CreateOneFormPage();
            LODOP.SET_PRINT_MODE("PRINT_SETUP_PROGRAM",true);
            if (LODOP.CVERSION)
                CLODOP.On_Return=function(TaskID,Value){
                    document.getElementById('scode').value=Value;
                    scode = Value;
                };
            LODOP.PRINT_SETUP();
        };

        function prn1_design() {
            object.printName = $('[name ="printName"]').val();
            if(!object.printName){
                layer.msg('请先填写模版名称!');return false;
            }
            object.kindId = $('#proKind').val();
            if(!object.kindId){
                layer.msg('请先选择产品分类!');return false;
            }
            object.isDefault = $('[name ="isDefault"]').val();
            object.width = $('[name ="width"]').val();
            object.height = $('[name ="height"]').val();
            if(!object.width && !object.height){
                layer.msg('请先设置纸张宽度和纸张高度!');return false;
            }
            object.pic = $('#pic').val();
            object.fontSize = $('[name ="fontSize"]').val();
            // if(!object.pic){
            //     layer.msg('请先上传logo!');return false;
            // }
            CreateOneFormPage();
            if (LODOP.CVERSION) CLODOP.On_Return=function(TaskID,Value){
                document.getElementById('scode').value=Value;
                scode = Value;
                console.log('prn1_design',scode);
            };
            LODOP.PRINT_DESIGN();
            // document.getElementById('scode').value = scode;
        };

        function prn1_preview() {
            LODOP = null;
            LODOP = getLodop();
            // LODOP.PRINT_INIT("设置标签排版维护");
            // LODOP.PRINT_INITA("1mm","1mm",object.pageWidth+"mm",object.pageHeight+"mm","设置标签排版维护");
            console.log('scode result' ,scode);
            eval(scode);

            LODOP.SET_LICENSES("常州易奇信息科技有限公司","664717080837475919278901905623","","");
            if (LODOP.CVERSION) CLODOP.On_Return=null;
            LODOP.PREVIEW();
        };

        function CreateOneFormPage(){
            LODOP = getLodop();
            // LODOP.PRINT_INIT("设置标签排版维护"+Math.random());
            LODOP.PRINT_INITA("1mm","1mm",object.width+"mm",object.height+"mm","设置标签排版维护"+Math.random());
            LODOP.SET_PRINT_PAGESIZE(1,object.width+"mm",object.height+"mm",'条码标签');
            LODOP.SET_LICENSES("常州易奇信息科技有限公司","664717080837475919278901905623","","");
            LODOP.SET_PRINT_MODE("PROGRAM_CONTENT_BYVAR",true);//生成程序时，内容参数有变量用变量，无变量用具体值

            if(scode){
                scode = scode.replace("LODOP.PRINT_INITA","// LODOP.PRINT_INITA");
                scode = scode.replace("LODOP.SET_PRINT_PAGESIZE","// LODOP.SET_PRINT_PAGESIZE");
                // LODOP.PRINT_INITA("1mm","1mm",object.width+"mm",object.height+"mm","设置标签排版维护"+Math.random());
                console.log(scode)
                eval(scode);
            }else{
                // 判断当前是否需要有Logo
                if(pic){
                    LODOP.ADD_PRINT_IMAGE("1mm","1mm","","8mm","<img border='0' src='"+object.pic+"'/>");
                    LODOP.SET_PRINT_STYLEA(0,"Stretch",2);//按原图比例(不变形)缩放模式
                    LODOP.SET_PRINT_STYLEA(0,"ContentVName","");
                }else{
                    LODOP.ADD_PRINT_TEXT("1mm","1mm",object.Width+"mm","6mm",object.compName);
                    LODOP.SET_PRINT_STYLEA(0,"FontSize",object.fontSize);
                    LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
                    LODOP.SET_PRINT_STYLEA(0,"ContentVName","object.compName");//设置内容参数的变量名
                }

                // 二维码
                LODOP.ADD_PRINT_BARCODE("1mm",(object.width-21)+"mm","15mm","15mm","QRCode",'我是条码内容');
                LODOP.SET_PRINT_STYLEA(0,"ContentVName","objectData.code");//设置内容参数的变量名

                let top = 8;
                for(var k in object.printConfig.filedList){
                    var temp = object.printConfig.filedList[k];

                    LODOP.ADD_PRINT_TEXT(top+"mm","2mm","22mm","6mm",temp.title);
                    LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
                    LODOP.SET_PRINT_STYLEA(0,"FontSize",object.fontSize);
                    // LODOP.SET_PRINT_STYLEA(0,"ContentVName","object.filedList."+temp.filed+'.title');//设置内容参数的变量名

                    LODOP.ADD_PRINT_TEXT(top+"mm","22mm","50mm","6mm",objectData[temp.filed]);
                    LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
                    LODOP.SET_PRINT_STYLEA(0,"FontSize",object.fontSize);
                    LODOP.SET_PRINT_STYLEA(0,"ContentVName",'objectData.'+temp.filed);//设置内容参数的变量名

                    top += 6;
                }
            }
        }

        function submit(){
            // console.log(JSON.stringify($('#fileds').val()));
            object.kindId = $('#proKind').val();
            if(!object.kindId){
                layer.msg('请先选择产品分类!');return false;
            }
            object.width = $('[name ="width"]').val();
            object.printName = $('[name ="printName"]').val();
            object.height = $('[name ="height"]').val();
            if(!object.width && !object.height){
                layer.msg('请先设置纸张宽度和纸张高度!');return false;
            }
            object.pic = $('#pic').val();
            id = $('#id').val();
            object.isDefault = $('[name ="isDefault"]').val();
            object.fontSize = $('[name ="fontSize"]').val();
            // object.fileds = object.fileds;
            console.log(object);
            // if(!scode){
            //     window.top.showMsg("请先设置排版",'error');
            //     return false;
            // }
            var params = {id:id,scode:scode,object:object};
            $.post('?controller=Jichu_ProKind&action=SaveSetPrintSenior',params,function(json){
                if(json.success){
                    window.top.showMsg("提交成功");
                }else{
                    window.top.showMsg(json.msg||'提交失败','error');
                }
            },'json');
        }
    </script>
</body>
</html>
